package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.UUID;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysLogs;
import com.ruoyi.system.service.ISysLogsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * logController
 * 
 * @author colin
 * @date 2021-08-11
 */
@RestController
@RequestMapping("/system/logs")
public class SysLogsController extends BaseController
{
    @Autowired
    private ISysLogsService sysLogsService;

    /**
     * 查询log列表
     */
    @PreAuthorize("@ss.hasPermi('system:logs:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLogs sysLogs)
    {
        startPage();
        List<SysLogs> list = sysLogsService.selectSysLogsList(sysLogs);
        return getDataTable(list);
    }

    /**
     * 导出log列表
     */
    @PreAuthorize("@ss.hasPermi('system:logs:export')")
    @Log(title = "log", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysLogs sysLogs)
    {
        List<SysLogs> list = sysLogsService.selectSysLogsList(sysLogs);
        ExcelUtil<SysLogs> util = new ExcelUtil<SysLogs>(SysLogs.class);
        return util.exportExcel(list, "log数据");
    }

    /**
     * 获取log详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:logs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysLogsService.selectSysLogsById(id));
    }

    /**
     * 新增log
     */
    @PreAuthorize("@ss.hasPermi('system:logs:add')")
    @Log(title = "log", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLogs sysLogs)
    {
        String uuid = UUID.randomUUID().toString();
        sysLogs.setId(uuid);
        return toAjax(sysLogsService.insertSysLogs(sysLogs));
    }

    /**
     * 修改log
     */
    @PreAuthorize("@ss.hasPermi('system:logs:edit')")
    @Log(title = "log", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLogs sysLogs)
    {
        return toAjax(sysLogsService.updateSysLogs(sysLogs));
    }

    /**
     * 删除log
     */
    @PreAuthorize("@ss.hasPermi('system:logs:remove')")
    @Log(title = "log", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysLogsService.deleteSysLogsByIds(ids));
    }
}
